package com.forum.model.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.AnnotationConfiguration;

@SuppressWarnings("deprecation")
public class SessionManager {

	private static final SessionFactory sessionFactory = buildSession();

	public static SessionFactory buildSession() {
		try {
			return new AnnotationConfiguration().configure()
					.buildSessionFactory();
		} catch (Throwable e) {
			System.out.println("Initial session factory creation failed!" + e);
		}

		return null;
	}

	public static SessionFactory getSessionFactory() {
		return sessionFactory;
	}

	public static boolean closeSession(Session session) {
		if (session.isOpen()) {
			session.close();
			return true;
		}
		return false;
	}
}